package model.search;

import java.util.List;

import model.basics.ClassRoom;
import model.basics.Instructor;
import model.basics.Request;
import model.time.TimeFrame;

/**
 * Objects of this class specifies the necessary information of a request accepted
 * 
 * @author Alexis 
 */

public class Order {
	private int idOrder;
	private Instructor anInstructor;
	private String courseToDictate;
	private ClassRoom aClassRoom;
	private List<TimeFrame> timeFrames;
	private int idRequest;
	private Request lastRequest;

	public int getIdOrder() {
		return idOrder;
	}

	public void setIdOrder(int idOrder) {
		this.idOrder = idOrder;
	}

	public Instructor getAnInstructor() {
		return anInstructor;
	}

	public void setAnInstructor(Instructor anInstructor) {
		this.anInstructor = anInstructor;
	}

	public String getCourseToDictate() {
		return courseToDictate;
	}

	public void setCourseToDictate(String courseToDictate) {
		this.courseToDictate = courseToDictate;
	}

	public ClassRoom getaClassRoom() {
		return aClassRoom;
	}

	public void setaClassRoom(ClassRoom aClassRoom) {
		this.aClassRoom = aClassRoom;
	}

	public List<TimeFrame> getTimeFrames() {
		return timeFrames;
	}

	public void setTimeFrames(List<TimeFrame> timeFrames) {
		this.timeFrames = timeFrames;
	}

	public int getIdRequest() {
		return idRequest;
	}

	public void setIdRequest(int idRequest) {
		this.idRequest = idRequest;
	}

	public Order(int idOrder, Instructor anInstructor, String courseToDictate,
			ClassRoom aClassRoom, List<TimeFrame> tf, Request req) {
		super();
		this.idOrder = idOrder;
		this.anInstructor = anInstructor;
		this.courseToDictate = courseToDictate;
		this.aClassRoom = aClassRoom;
		this.timeFrames = tf;
		this.idRequest = req.getId();
		this.lastRequest=req;
	}

	// /////////////////////////////

	
	public Request getLastRequest() {
		return lastRequest;
	}

	public void setLastRequest(Request lastRequest) {
		this.lastRequest = lastRequest;
	}

	/**
	 * This method return the first request of a specific order
	 * @param idReq
	 * @param rs
	 * @return Request
	 * 
	 * */
	public Request showOriginalRequest(int idReq, List<Request> rs) {
		// established numeration, ej: 001xxx
		// its not important the order of the request

		int numReqOriginal = (idReq / 1000) * 1000; // id of original request
		int count = 0;
		int rsSize = rs.size() - 1;	//it takes values of the list to n-1
		while (rs.get(count).getId() != numReqOriginal && count < rsSize)
			count++;

		return rs.get(count);
	}

	/**
	 * Modifies the actual Order
	 * @param i2
	 * @param string
	 * @param cr
	 * @param tfs
	 * 
	 * */
	
	public void modifyOrder(Instructor i2, String string, ClassRoom cr,
			List<TimeFrame> tfs) {

		this.setaClassRoom(cr);
		this.setAnInstructor(i2);
		this.setTimeFrames(tfs);
		this.setCourseToDictate(string);
	}

}
